<% add_decidim_page_title(t("new", scope: "decidim.initiatives.create_initiative.select_initiative_type")) %>
<% default_type = available_initiative_types.first %>
<% announcement_body = capture do %>
  <%= t("select_initiative_type_help_html", scope: "decidim.initiatives.create_initiative.select_initiative_type") %>
  <br>
  <%= link_to t("more_information", scope: "decidim.initiatives.create_initiative.select_initiative_type"), decidim.page_path("initiatives", locale: current_locale), target: "_blank", class: "button button__sm button__text-secondary block text-left" %>
<% end %>

<%= cell("decidim/announcement", { body: announcement_body }, callout_class: "secondary") %>

<h3 class="title-decorator text-2xl mt-8"><%= t(".subtitle") %></h3>

<div class="initiatives__selection" id="select-initiative-type">
  <%= decidim_form_for(@form, url: select_initiative_type_create_initiative_index_path(locale: current_locale), method: :put, html: { id: "new_initiative_form", class: "form-defaults " }) do |f| %>
    <% initiative_types_each do |type| %>
      <% is_allowed = allowed_to?(:create, :initiative, { initiative_type: type }) %>

      <%= render layout: "decidim/application/radio_accordion",
                 locals: {
                   panel_id: type.id,
                   title: translated_attribute(type.title),
                   input_radio_name: "initiative[type_id]",
                   input_radio_value: type.id,
                   show_more_text: t("show_more", scope: "decidim.initiatives.create_initiative.select_initiative_type"),
                   show_less_text: t("show_less", scope: "decidim.initiatives.create_initiative.select_initiative_type"),
                   disabled: !is_allowed
                 } do %>
        <p>
          <%= decidim_sanitize_admin(translated_attribute(type.description)) %>
        </p>

        <% if !is_allowed %>
          <p>
            <%= action_authorized_link_to(
                :create,
                fill_data_create_initiative_index_path(initiative: { type_id: type.id }, locale: current_locale),
                authorizations_modal_path: authorization_create_modal_initiative_path(type, locale: current_locale),
                permissions_holder: type,
                class: "button button__sm button__transparent-secondary",
                "data-dialog-open": "not-authorized-modal",
                onclick: "event.preventDefault();"
              ) do %>
              <%= t("verification_required", scope: "decidim.initiatives.create_initiative.select_initiative_type") %>
            <% end %>
          </p>
        <% end %>

        <p>
          <%= link_to t("consult_existing_initiatives", scope: "decidim.initiatives.create_initiative.select_initiative_type"),
                      initiatives_path(filter: { with_any_type: type.id },locale: current_locale), target: "_blank" %>
        </p>
      <% end %>
    <% end %>

    <div class="form__wrapper-block flex-col-reverse md:flex-row justify-between border-0">
      <%= f.submit t(".continue"), class: "button button__sm md:button__lg button__secondary" %>
    </div>
  <% end %>
</div>

<%= render partial: "decidim/initiatives/modal" %>
